package cn.ibizlab.util.adapter.config;

import cn.ibizlab.util.adapter.aspect.SysRuntimeAdapterAspect;
import org.springframework.aop.Pointcut;
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;

/**
 * 实体逻辑动态切面配置
 */
@Configuration
public class DynamicPointcutAdvisorConfig {

    @Value("${ibiz.runtime.pointcut:}")
    private String pointcut;
    @Autowired
    SysRuntimeAdapterAspect sysRuntimeAdapterAspect;

    /**
     * 设置执行处理逻辑的切点
     * @return
     */
    public Pointcut pointcut() {
        Assert.hasLength(pointcut,"未配置系统运行时服务路径");
        AspectJExpressionPointcut expressionPointcut = new AspectJExpressionPointcut();
        expressionPointcut.setExpression(pointcut);
        return expressionPointcut;
    }

    /**
     * 设置处理逻辑的切面配置
     * @returnK
     */
    @Bean
    public DefaultPointcutAdvisor pointcutAdvisor() {
        DefaultPointcutAdvisor defaultPointcutAdvisor = new DefaultPointcutAdvisor();
        defaultPointcutAdvisor.setPointcut(pointcut());
        defaultPointcutAdvisor.setAdvice(sysRuntimeAdapterAspect);
        return defaultPointcutAdvisor;
    }
}
